package com.syni.mdd.sjb.common.datatreaure.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.entity.DankApplication;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.mapper.DankApplicationMapper;
import com.syni.mdd.sjb.common.component.utils.common.utils.BeanUtils;
import com.syni.mdd.sjb.common.datatreaure.service.DankApplicationService;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rp.dataBankBusiness.ApplicationListVo;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lcc
 * @since 2020-09-21
 */
@Service
public class DankApplicationServiceImpl extends ServiceImpl<DankApplicationMapper, DankApplication> implements DankApplicationService {

    public static Map<Integer,String> appTypeMap = new HashMap<>();

    static {
        appTypeMap.put(1,"营销工具");
        appTypeMap.put(2,"数据管理");
        appTypeMap.put(3,"经营管理");
        appTypeMap.put(4,"社群功能");
        appTypeMap.put(5,"其他功能");
    }


    @Override
    public List<ApplicationListVo> getApplicationList() {
        QueryWrapper queryWrapper = new QueryWrapper<DankApplication>()
                .orderByAsc(DankApplication.APP_TYPE,DankApplication.NEW_TIME);
        List<DankApplication> dankApplications = this.list(queryWrapper);
        List<ApplicationListVo> appLists = BeanUtils.copyList(dankApplications, ApplicationListVo.class);
        for(ApplicationListVo a : appLists){
            a.setTypeName(appTypeMap.get(a.getAppType()));
        }
        return appLists;
    }

    @Override
    public List<DankApplication> getAppByIds(List<Integer> ids) {
        QueryWrapper queryWrapper = new QueryWrapper<DankApplication>()
                .in(DankApplication.ID,ids)
                .orderByAsc(DankApplication.APP_TYPE,DankApplication.NEW_TIME);
        List<DankApplication> appList = this.list(queryWrapper);
        return appList;
    }

    @Override
    public DankApplication getAppByName(String name) {
        QueryWrapper queryWrapper = new QueryWrapper<DankApplication>()
                .eq(DankApplication.APP_NAME,name);
        return this.getBaseMapper().selectOne(queryWrapper);
    }


}
